﻿<!DOCTYPE html>
<html>
<head>
    <script src="/js/header.js"></script>
    <link href="/lib/easyui/default/easyui.css" rel="stylesheet" />
    <link href="/lib/sumoselect/sumoselect.css" rel="stylesheet" />
    <script src="/lib/date/wdatepicker.js"></script>
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/lib/bootstrap/jquery.bootstrap-pureClearButton.js"></script>
    <script type="text/javascript" src="/lib/sumoselect/jquery.sumoselect.js"></script>
</head>
<body>
    <div class="data-wrap case">

        <form class="form-inline" id="formSearch">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <!--<span class="glyphicon glyphicon-plus"></span>-->
                    <a class="btn btn-default btn-sm paymentRecord0002 hide gettext" data-modal="/view/payment/paymentrecordAdd.html" data-title="新增" data-width="452" data-height="440">新增</a>
                    <!--<span class="glyphicon glyphicon glyphicon-download"></span>-->
                    <a class="btn btn-default btn-sm paymentRecordExport PaymentRecord0011 hide gettext" href="javascript:void(0)" data-title="导出">导出</a>
                </div>
                <div class="pull-right">

                    <input type="hidden" name="companyId" />

                    <div class="input-group input-group-sm">
                        <div class="input-sm"><input name="autoRefresh" type="checkbox" title="10秒自动刷新" /> <label id="time" class="wd125 gettext">10秒自动刷新</label></div>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">公司名称：</label>
                        <select multiple="multiple" class="search-box-sel-all" name="searchCompanyIds" style="height: 31px;padding: 3px 12px;width:150px;"></select>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">客户单号：</label>
                        <input class="form-control wd125" name="withdrawalOrderNo" type="text" autocomplete="off">
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">创建时间：</label>
                        <input id="d421" class="Wdate wd175" name="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />
                        --<input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">付款结果：</label>
                        <select class="form-control gettext" name="paymentStatus">
                            <option value="">请选择</option>
                            <option value="1">未付款</option>
                            <option value="2">付款成功</option>
                            <option value="3">付款失败</option>
                            <option value="4">付款中</option>
                            <option value="5">取消付款</option>
                            <option value="6">异常</option>
                        </select>
                    </div>

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">通知状态：</label>
                        <select class="form-control gettext" name="noticeStatus">
                            <option value="">请选择</option>
                            <option value="1">未通知</option>
                            <option value="2">通知成功</option>
                            <option value="3">通知失败</option>
                            <option value="4">通知中</option>
                        </select>
                    </div>

                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                    <button type="button" class="btn btn-default btn-sm gettext" id="AdvSearch">高级搜索</button>

                </div>
            </div>
            <!--一高级搜索开始-->
            <div class="AdvSearch">
                <div class="AdvSearchcom collapse">
                    <table>
                        <tbody>
                            <tr>
                                <td class="gettext">客户姓名：</td>
                                <td><input class="form-control" name="withdrawalAccountName" type="text" autocomplete="off"></td>
                                <td class="gettext">客户卡号：</td>
                                <td><input class="form-control" name="withdrawalCardNumber" type="text" autocomplete="off"></td>
                            </tr>
                            <tr>
                                <td class="gettext">付款名称：</td>
                                <td><input class="form-control" name="cardName" type="text" autocomplete="off"></td>
                                <td class="gettext">订单号：</td>
                                <td><input class="form-control" name="orderNo" type="text" autocomplete="off"></td>
                            </tr>
                            <tr>
                                <td class="gettext">付款类型：</td>
                                <td>
                                    <select class="" name="paymentType"></select>
                                </td>
                                <td class="gettext">银行名称：</td>
                                <td><input class="form-control" name="bankName" type="text" autocomplete="off"></td>

                            </tr>
                        </tbody>
                    </table>
                    <div class="AdvSearchfooter t_c">
                        <button id="search" class="btn btn-default btn-sm gettext" type="button">立即搜索</button>
                        <button id="cancel" data-dismiss="modal" class="btn btn-default btn-sm gettext" type="button">取消</button>
                    </div>
                </div>
            </div>
        </form>

        <!--高级搜索结束-->
        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="easyui-datagrid" id="paymentRecord" style="height:500px;"></table>
                </div>
            </div>
        </div>
    </div>


    <script src="/js/page/paymentrecord.js?v=201908131326"></script>
    <script type="text/javascript">

        var wait = 10;

        var autoRefresh = $("input[name='autoRefresh']");
        var paymentType = $("select[name='paymentType']");
        var searchCompanyIds = $("select[name='searchCompanyIds']");

        var pageSize = 50;

        $(function () {

            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            if (d == 1) {
                var startTime = y + "-" + (m < 10 ? '0' + m : m) + "-" + (d < 10 ? '0' + d : d);
                var endTime = y + "-" + (m < 10 ? '0' + m : m) + "-" + (d < 10 ? '0' + d : d);

                $("input[name='startTime']").val(startTime + " 00:00:00");
                $("input[name='endTime']").val(endTime + " 23:59:59");
            } else {
                $("input[name='startTime']").val(FlashPay.Util.GetDateStr(-1) + " 00:00:00");
                $("input[name='endTime']").val(FlashPay.Util.GetDateStr(0) + " 23:59:59");
            }

            FlashPay.UI.DataAutoHeight();

            FlashPay.UI.Triggerbox({
                btnAdvSearch: '#AdvSearch',
                searchCallBack: function () {
                    window.currentPage = null;
                    doSearch();
                },
                cancelCallBack: function () {

                }
            });

            $("#btnSearch").click(function () {
                window.currentPage = null;

                doSearch();
            });

            $(autoRefresh).change(function () {
                wait = 10;
                time();
            });

            FlashPay.UI.DoSearch();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/payment/GetSysConfig",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.success) {
                        if (res.data != null) {
                            var selectText = $.i18n.singleReplace("请选择")

                            paymentType.append("<option value=''>" + selectText + "</option>");
                            
                            $.each(res.data, function (i, item) {
                                var text = $.i18n.singleReplace(item.configContent)
                                if (!FlashPay.Util.isNullOrEmptySpance(text)) {
                                    paymentType.append("<option value='" + item.configValue + "'>" + text + "</option >");
                                } else {
                                    paymentType.append("<option value='" + item.configValue + "'>" + item.configContent + "</option >");
                                }
                            });
                        }
                    }
                }
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Role/GetCompany",
                data: null,
                success: function (response) {
                    if (response.success) {

                        searchCompanyIds.empty();
                        if (response.data != null) {
                            $.each(response.data, function (i, item) {
                                searchCompanyIds.append("<option value='" + item.companyID + "'>" + item.companyName + "</option >");
                            });
                            searchCompanyIds.SumoSelect({ okCancelInMulti: true, selectAll: true });
                        }
                        //cover.Remove();
                    } else {
                        //cover.Remove();
                    }
                },
                error: function (e) {
                    cover.Remove();
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/payment/PaymentRecordAddAuth",
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.success) {
                        if (res.statusCode == 'PaymentRecord0002') {
                            $("a.paymentRecord0002").removeClass("hide");
                        } else {
                            $("a.paymentRecord0002").remove();
                        }

                        if (res.errorCode == 'PaymentRecord0011') {
                            $("a.PaymentRecord0011").removeClass("hide");
                        } else {
                            $("a.PaymentRecord0011").remove();
                        }
                    }
                }
            });

            FlashPay.Util.Language();

            $(".paymentRecordExport").click(function () {

                var query = $("#formSearch").serializeObject();
                //var query = {}

                //query.startTime = $("input[name='startTime']").val();
                //query.endTime = $("input[name='endTime']").val();

                //var companyName = $("input[name='companyName']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
                //    query.companyName = companyName;
                //}

                //var orderNo = $("input[name='orderNo']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(orderNo)) {
                //    query.orderNo = orderNo;
                //}

                //var paymentStatus = $("select[name='paymentStatus']").find("option:selected").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(paymentStatus)) {
                //    query.paymentStatus = paymentStatus;
                //}

                //var noticeStatus = $("select[name='noticeStatus']").find("option:selected").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(noticeStatus)) {
                //    query.noticeStatus = noticeStatus;
                //}

                //var withdrawalOrderNo = $("input[name='withdrawalOrderNo']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(withdrawalOrderNo)) {
                //    query.withdrawalOrderNo = withdrawalOrderNo;
                //}

                //var withdrawalAccountName = $("input[name='withdrawalAccountName']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(withdrawalAccountName)) {
                //    query.withdrawalAccountName = withdrawalAccountName;
                //}

                //var withdrawalCardNumber = $("input[name='withdrawalCardNumber']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(withdrawalCardNumber)) {
                //    query.withdrawalCardNumber = withdrawalCardNumber;
                //}

                //var cardName = $("input[name='cardName']").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(cardName)) {
                //    query.cardName = cardName;
                //}

                //var paymentType = $("select[name='paymentType']").find("option:selected").val();
                //if (!FlashPay.Util.isNullOrEmptySpance(paymentType)) {
                //    query.paymentType = paymentType;
                //}

                FlashPay.UI.Confirm({
                    content: "下载付款记录需要花费大量时间,确认要下载吗？",
                    ok: function () {
                        var cover = FlashPay.UI.Mask({
                            obj: $("body"),
                            opacity: 0.5
                        });

                        FlashPay.Util.Ajax({
                            url: '/Payment/PaymentRecordExport',
                            type: 'POST',
                            data: { query: query },
                            success: function (response) {
                                if (response.success) {
                                    cover.Remove();

                                    if (response.data != null && response.data.length > 0) {
                                        var body = '<table>';

                                        $.each(response.data, function (i, item) {
                                            body += '<tr>';
                                            body += '<td>' + item.orderNo + '</td>';
                                            body += '<td>' + item.companyName + '</td>';
                                            body += '<td>' + item.withdrawalOrderNo + '</td>';
                                            body += '<td>' + item.bankName + '</td>';
                                            body += '<td>' + item.cardName + '</td>';
                                            body += '<td>' + item.cardNumber + '</td>';
                                            body += '<td>' + item.withdrawalAmount + '</td>';
                                            body += '<td>' + item.withdrawalFee + '</td>';
                                            body += '<td>' + item.createDbdate + '</td>';
                                            body += '<td>' + item.paymentStatus + '</td>';
                                            body += '<td>' + item.withdrawalAccountName + '</td>';
                                            body += '<td>' + item.withdrawalBankName + '</td>';
                                            body += '<td>' + item.withdrawalCardNumber + '</td>';
                                            body += '<td>' + item.paymentDate + '</td>';
                                            body += '<td>' + item.depositType + '</td>';
                                            body += '<td>' + item.noticeStatus + '</td>';
                                            body += '<td>' + item.noticeLastDate + '</td>';
                                            body += '<td>' + item.noticeTimes + '</td>';
                                            body += '<td>' + item.paymentType + '</td>';
                                            body += '</tr>';
                                        });

                                        body += '</table>';

                                        var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
                                        excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
                                        //excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
                                        //excelFile += '; charset=UTF-8">';
                                        excelFile += "<head>";
                                        excelFile += "<!--[if gte mso 9]>";
                                        excelFile += "<xml>";
                                        excelFile += "<x:ExcelWorkbook>";
                                        excelFile += "<x:ExcelWorksheets>";
                                        excelFile += "<x:ExcelWorksheet>";
                                        excelFile += "<x:Name>";
                                        excelFile += "Sheet1";
                                        excelFile += "</x:Name>";
                                        excelFile += "<x:WorksheetOptions>";
                                        excelFile += "<x:DisplayGridlines/>";
                                        excelFile += "</x:WorksheetOptions>";
                                        excelFile += "</x:ExcelWorksheet>";
                                        excelFile += "</x:ExcelWorksheets>";
                                        excelFile += "</x:ExcelWorkbook>";
                                        excelFile += "</xml>";
                                        excelFile += "<![endif]-->";
                                        excelFile += "</head>";
                                        excelFile += "<body>";
                                        excelFile += body;
                                        excelFile += "</body>";
                                        excelFile += "</html>";

                                        var uri = window.URL.createObjectURL(new Blob([excelFile], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }));//'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
                                        var link = document.createElement("a");
                                        link.href = uri;

                                        link.style = "visibility:hidden";
                                        link.download = response.statusCode + ".xlsx";

                                        document.body.appendChild(link);
                                        link.click();
                                        document.body.removeChild(link);
                                    }
                                    else {
                                        cover.Remove();
                                        FlashPay.UI.Tip_short_warning("暂无记录");
                                    }

                                } else {
                                    cover.Remove();
                                    FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                                }
                            },
                            error: function (json) {
                                cover.Remove();
                                FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                            }
                        });
                    }
                });

            });
        });

        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                FlashPay.UI.DoSearch();
            }
        });

        //倒时计
        function time() {

            var language = FlashPay.Util.Language();

            var obj = document.getElementById("time");

            var isauto = $(autoRefresh).is(':checked');
            if (!isauto) {

                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = "10 Second Refresh";
                } else {
                    obj.innerText = "10 秒自动刷新";
                }
                

                return false;
            }

            if (wait == 0) {
                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = "10 Second Refresh";
                } else {
                    obj.innerText = "10秒自动刷新";
                }
                
                wait = 10;

                if (isauto) {
                    setTimeout(function () { time(); }, 1000);
                }

                FlashPay.UI.DoSearch();
            } else {

                
                if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
                    obj.innerText = wait + " Second Refresh";
                } else {
                    obj.innerText = wait + "秒自动刷新";
                }
                wait--;
                setTimeout(function () { time(); }, 1000);
            }
        }

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function Tip_short_warning(word) {
            FlashPay.UI.Tip_short_warning(word);
        }

        function view(obj) {
            eval(function (p, a, c, k, e, r) { e = String; if (!''.replace(/^/, String)) { while (c--) r[c] = k[c] || c; k = [function (e) { return r[e] }]; e = function () { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p }('5.6.7($(0).1("8"),{2:$(0).1("2"),3:$(0).1("3"),4:$(0).1("4")});', 9, 9, 'obj|data|title|width|height|FlashPay|UI|DialogOpen|href'.split('|'), 0, {}))
        }

        function dialogOpen(obj) {

            var modal = $(obj);

            var url = modal.data("url");

            FlashPay.UI.DialogOpen(url, {
                title: modal.data("title"),
                width: modal.data("width"),
                height: modal.data("height"),
                init: function () {
                    this.button(
                        {
                            name: "保存",
                            callback: function () {
                                var iframe = this.iframe.contentWindow;
                                if (!iframe.document.body) {
                                    return false;
                                }
                                iframe.save();
                                return false;
                            },
                            focus: true,
                        },
                        {
                            name: '取消'
                        }
                    );
                }
            });
        }
    </script>
</body>
</html>